package com.njuse.jvmfinal.runtimestructure;

import java.nio.ByteBuffer;

import com.njuse.jvmfinal.Starter;
import com.njuse.jvmfinal.Instruction.Instruction;

public class interpreter {
   
	
   public static void interpret(Jthread thread) {
	   ByteBuffer reader;
	   while (thread.getTop()!=0) {
		   Jframe frame=thread.getFrames().get(thread.getFrames().size()-1);
		   byte[] source=frame.getMymethod().getCode();
		   reader=ByteBuffer.wrap(source);
		   reader.position(frame.getPc());
           int opcode = reader.get() & 0xff;
           Instruction instruction = decoder.decode(opcode);
           instruction.readindex(reader);
           frame.setPc(reader.position());
       //    Starter.ins=Starter.ins+instruction.getClass().getName()+" "+frame.getMymethod().getName()+"\n";
           instruction.execute(frame);

	   }
   }
}
